package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCTest {

    public static void main(String[] args) throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/cgb2015?characterEncoding=utf8";
        String user="root";
        String pwd="root";
        //2.连接数据库
        Connection conn = DriverManager.getConnection(url,user,pwd);
        //3.获取传输器
        Statement st = conn.createStatement();
        String sql="select * from emp";
        //4.执行sql
        ResultSet rs=/*执行sql*/st.executeQuery(sql);
        //解析结果集
        if(rs.next()){
            System.out.println("查询成功");
        }else {
            System.out.println("查询失败");
        }
        rs.close();
        st.close();
        conn.close();


    }
}
